package com.imooc.message;

import com.imooc.dto.OrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2019/3/20.
 * spring cloud stream的使用，接收消息
 */
@Component
@EnableBinding(StreamClient.class)
@Slf4j
public class StreamReceiver {

    /*@StreamListener(value = StreamClient.INPUT)
    public void process(Object message) {
        log.info("StreamReceiver: {}",message);
    }*/

    //接收对象
    @StreamListener(value = StreamClient.INPUT)
    @SendTo(StreamClient.INPUT2)  //接收到消息后将结果返回
    public String process(OrderDTO message) {

        log.info("StreamReceiver: {}",message);
        return "received.";
    }

    @StreamListener(value = StreamClient.INPUT2)
    public void process2(String message) {

        log.info("StreamReceiver2: {}",message);
    }


}
